#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5;
const int MOD=1e9+7;
struct Mat{
    ll m[N][N];

    void print(){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                printf("%lld ",m[i][j]);
            }
            printf("\n");
        }
    }
};
Mat operator *(Mat a,Mat b){
    Mat t;
    memset(t.m,0,sizeof(t.m));
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            if(a.m[i][k]==0){
                continue;
            }
            for(int j=0;j<N;j++){
                if(b.m[k][j]==0){
                    continue;
                }
                t.m[i][j]+=(a.m[i][k]%MOD*b.m[k][j]%MOD)%MOD;
            }
        }
    }
    return t;
}
Mat operator ^(Mat a,int n){
    Mat res;
    memset(res.m,0,sizeof(res.m));
    for(int i=0;i<N;i++){
        res.m[i][i]=1;
    }
    while(n){
        if(n%2){
            res=res*a;
        }
        n/=2;
        a=a*a;
    }
    return res;
}
ll x,y;
int n;
ll exgcd(ll a,ll b,ll &x,ll &y){

}
int main(void){
    scanf("%lld%lld",&x,&y);
    scanf("%d",&n);
    Mat f,a;
    memset(f.m,0,sizeof(f.m));
    memset(a.m,0,sizeof(a.m));
    f.m[0][0]=y;
    f.m[0][1]=x;
    f.m[0][2]=1;
    a.m[0][0]=1;
    a.m[1][0]=-1;
    a.m[0][1]=1;
    a.m[1][2]=1;
    //f.print();
    //a.print();
    //(f*a^1).print();
    if(n==1){
        printf("%lld\n",(x%MOD+MOD)%MOD);
        return 0;
    }
    ll ans=((f*(a^(n-2))).m[0][0]%MOD+MOD)%MOD;
    printf("%lld\n",ans);
    return 0;
}